<template>
    <div class="app-container">
        <!-- <v-GetToolBar align="right" :MenuCode="MenuCode" :IsfunEdit='IsfunEdit' :Isfunfail='Isfunfail'
            @handeAdd='handeAdd' @handleEdit='handleEdit' @OpenFindForm='OpenFindForm'
            @handlexportData='handlexportData' @IsfunEdit='handleIsfunEdit' @IsfunDelete='handleIsfunfail'
            @handleclose='handleclose'></v-GetToolBar> -->

        <el-row>
            <el-col :span="17">
                <Search-Form class="searchTop" ref="form" size='mini' labelWidth='50px' :searchData='SearchSSN'
                    :tableCols='tableColsCode'  :searchHandle="searchHandle"></Search-Form>
            </el-col>
            <el-col :span="7">
                <div class="botton">
                    <el-button type="primary" size="small" class="botn" @click="searchData"> <i
                            class="el-icon-tickets"></i>查询</el-button>
                    <el-button type="primary" size="small" class="botn" @click="addOrder"> <i
                            class="el-icon-tickets"></i>添加</el-button>
                    <el-button type="success" size="small" class="botn" @click="addSerial"> <i
                            class="el-icon-tickets"></i>配方</el-button>
                    <el-button type="info" size="small" class="botn" @click="autoOrder"> <i
                            class="el-icon-tickets"></i>自动</el-button>
                    <el-button type="warning" size="small" class="botn" @click="pushOrder"> <i
                            class="el-icon-tickets"></i>确认</el-button>
                </div>
            </el-col>
        </el-row>

        <div class="ces-mainopen">
            <div class="main" style="width: 224px;margin-right: 4px;">
                <ces-table :ToolBarheight='445' size='mini' :isSelection='false' :isIndex='true' :isSearch='false'
                    :isHandle='false' :StepSN='0' :IsfunEdit='IsfunEdit' :Isfunfail='Isfunfail' :tableData='tableData'
                    :tableColumns='tableCols' :pagination='Search' :split="true" @refresh="refresh"
                    @handleEdit='handleEdit' @handleDelete='delData' :tableLoading="tableLoading[0]"
                    @workbookInitialized="workbookInitialized" @selectChanged="selectChanged" :remark="0" :sysID="0">
                </ces-table>
            </div>



            <div class="main" style="width: 60vw;flex-grow: 1;">
                <ces-table :ToolBarheight='495' size='mini' :isSelection='false' :isIndex='true' :isSearch='true'
                    :isHandle='false' :StepSN='0' :IsfunEdit='IsfunEdit' :Isfunfail='Isfunfail'
                    :tableData='tableDataCode' :tableColumns='tableColsCode' :pagination='SearchSSN' @refresh="refresh"
                    @handleEdit='handleEdit' @handleDelete='delData' :tableLoading="tableLoading[0]"
                    @workbookInitialized="workbookInitialized" @selectChanged="selectChanged" :remark="1" :sysID="1">
                </ces-table>
            </div>

            <div class="main" style="width: 80vw;flex-grow: 1;">
                <ces-table :ToolBarheight='460' size='mini' :isSelection='false' :isIndex='true' :isSearch='false'
                    :isHandle='false' :StepSN='0' :IsfunEdit='IsfunEdit' :Isfunfail='Isfunfail' :hidden="false"
                    :tableData='tableDataThree' :tableColumns='tableColsThree' :pagination='SearchBody'
                    @refresh="refresh" @handleEdit='handleEdit' @handleDelete='delData' :tableLoading="tableLoading[0]"
                    @workbookInitialized="workbookInitialized" @selectChanged="selectChanged" :remark="2" :sysID="2">
                </ces-table>
            </div>

            <!-- {{ see }}
            <br><br><br> -->
            <!-- {{ see1 }} -->
        </div>

    </div>
</template>

<script>


//引入组件
const GCsheets = GC.Spread.Sheets;
import '@grapecity/spread-sheets-vue';
import GC from '@grapecity/spread-sheets';
import '@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css';
import '@grapecity/spread-sheets/js/zh.js';
import { mapState } from 'vuex';
GC.Spread.Common.CultureManager.culture('zh-cn');
import cesTable from "../Common//ComSpreadTable.vue";
import { HeaderCheckBoxCellType } from '@/static/data.js';

import ComVxeTable from "../Common/ComVxeTable.vue";
import SearchForm from "../Common/Search.vue";
import MianForm from "../Common/form.vue";

import { funDownload, GetTableColsData } from "@/api/Common";


import { getDataList, UpdateForm, DeleteForm, DeleteRow, getfunDownload } from '@/api/Loading/Loading'; //更改


import { CloseForm } from '@/api/System';
import vGetToolBar from "../Common/GetToolBar";

export default {
    //Collection/BarcodePrinting
    name: "StuffingFormOpenVxe",
    data() {
        //表单查询一般分为input，下拉框，和日期，下面是下拉框时的设置下拉信息的情况，我的项目没有用到，但是留着方便看

        return {
            key: 1,
            see: [],
            see1: [],
            spread: [[], [], []],
            selectionData: [[], [], []],
            Indexs: null,
            tableLoading: [false, false, false, false],
            FCUSTID: null,
            MenuCode: "A050106",
            tableData: [],//表格数据
            tableCols: [],//表格列数据
            searchHandle: [],
            billID: "",
            IsfunEdit: false,
            Isfunfail: true,
            SearchWO: {
                // 查询条件
                total: 0, // 总记录数
                pageSize: 0, // 一页显示的记录数
                page: 1, // /当前页码
                RNO: "1620", // 表编号  根据Controller中对应的表编号
                InterID: "1620",
                jsWhere: "", // 自定义条件
                Download: ""
                // Status: 0,
                //   BillState: "BillStateALL",
            },
            SearchSSN: {
                // 查询条件
                total: 0, // 总记录数
                pageSize: 100, // 一页显示的记录数
                page: 1, // /当前页码
                RNO: "1624", // 表编号  根据Controller中对应的表编号
                InterID: "1624",
                jsWhere: "", // 自定义条件
                IsFieldText: '0',
                Download: "",
                Customer: '',
                FCUSTID: '',
                Name: '',
                ProductNo: '',
                ModifyedOn: [],
                // Status: 0,
                //   BillState: "BillStateALL",
            },
            SearchBody: {
                // 查询条件
                total: 0, // 总记录数
                pageSize: 1000, // 一页显示的记录数
                page: 1, // /当前页码
                RNO: "1624", // 表编号  根据Controller中对应的表编号
                InterID: "1624",
                jsWhere: "", // 自定义条件
                // IsFieldText: '0',
                Download: ""
                // Status: 0,
                //   BillState: "BillStateALL",
            },
            SearchDialog: false,
            DialogBtnMargin: 0,
            dialogVisible: false,
            dialogFormVisible: false,
            form: {
                name: '',
                region: '',
                date1: '',
                date2: '',
                delivery: false,
                type: [],
                resource: '',
                desc: ''
            },
            tableDataThree: [],
            tableColsThree: [],
            WO: '',
            PrdName: '',
            radio: '3',
            row: [],
            createQty: null,
            count: null,
            selectCode: [],
            SelectData: {},
            reCode: {},
            tableDataCode: [],
            tableColsCode: [],
            multipleTable: [],
            formInline: {
                user: '',
                region: ''
            },
            SearchData: {},

        }
    },

    components: { //引入组件后注册组件
        vGetToolBar,
        SearchForm,
        MianForm,
        ComVxeTable,
        cesTable
    },
    mounted() {

        this.getDataList()
        // this.SearchCode.total = 12;
    }, props: {
        ParmType: String,
        index: Int16Array,
    },
    methods: {
        workbookInitialized: function (workbook, remarkTb) {
            this.spread[remarkTb] = workbook;
        },
        // workbookInitialized: function (workbook, remarkTb) {
        //     this.spread[remarkTb] = workbook;
        // },
        selectChanged(newValue, remarkTb) {
            // 在子组件计算属性发生变化时，更新父组件的计算属性
            this.selectionData = newValue;
        },
        async setData(remarkTb, tableCols, tableData) {

            this.spread[remarkTb].suspendPaint();
            let sheet = this.spread[remarkTb].getActiveSheet();



            sheet.options.protectionOptions.allowSort = false;
            sheet.options.protectionOptions.allowFilter = false;
            //       sheet.options.allowCellOverflow = true;
            sheet.defaults.rowHeight = 23;
            sheet.defaults.colWidth = 100;
            sheet.defaults.colHeaderRowHeight = 23;
            sheet.defaults.rowHeaderColWidth = 60;
            this.spread[remarkTb].options.tabStripVisible = false; //是否显示表单标签
            let colHeader1 = [];
            let colInfos = [];

            sheet.setDataSource(tableData);



            tableCols.forEach((x, y) => {
                //列宽
                // sheet.setColumnWidth(y, x['width'],GC.Spread.Sheets.SheetArea.viewport); // 注意：列索引从0开始  

                x['name'] = x['prop'];
                x['displayName'] = x['label'];
                x['width'] = parseInt(x.width);
                if (x.prop === 'isChecked') {
                    // 选框
                    sheet.setCellType(
                        0,
                        0,
                        new HeaderCheckBoxCellType(),
                        GCsheets.SheetArea.colHeader,
                    );
                    x.cellType = new GC.Spread.Sheets.CellTypes.CheckBox();
                } else if (
                    x.type === 'comboboxMultiple' ||
                    x.type === 'combobox' || x.type === 'Select'
                ) {
                    if (x.ValueMember) {

                        let newData = []; // 设置列表每行下拉菜单
                        x.ColsRowDate.map((item, index) => {

                            let row = {
                                text: item.label,
                                value: item.value,
                            };
                            newData.push(row);


                        });

                        let sheet = this.spread[remarkTb].getActiveSheet();
                        let count = sheet.getRowCount(GC.Spread.Sheets.SheetArea.viewport);
                        let style = new GC.Spread.Sheets.Style();
                        style.hAlign = GC.Spread.Sheets.HorizontalAlign.center;
                        style.vAlign = GC.Spread.Sheets.VerticalAlign.bottom;
                        // sheet.setStyle(j, i, style);

                        tableData.forEach((x, y1) => {
                            //居中
                            sheet.setStyle(y1, y, style);
                            // 获取要绑定下拉菜单的单元格对象
                            let cell = sheet.getCell(y1, y);
                            // 创建下拉菜单单元格类型，并设置其选项数据
                            let comboBox = new GC.Spread.Sheets.CellTypes.ComboBox();
                            comboBox.editorValueType(
                                GC.Spread.Sheets.CellTypes.EditorValueType.value,
                            );
                            comboBox.editable(true);
                            // 获取下拉菜单的选项数据
                            comboBox.items(newData);
                            comboBox.itemHeight(24);
                            // 将下拉菜单单元格类型绑定到指定的单元格中
                            cell.cellType(comboBox);
                            // debugger
                        })
                    }


                } else if (x.type === 'checkbox') {
                    let cellType = new GC.Spread.Sheets.CellTypes.CheckBox();
                    cellType.caption('');
                    cellType.textTrue('');
                    cellType.textFalse('');
                    cellType.textIndeterminate('');
                    cellType.textAlign(
                        GC.Spread.Sheets.CellTypes.CheckBoxTextAlign.center,
                    );
                    cellType.isThreeState(false);
                    sheet.getCell(-1, y).cellType(cellType);
                } else if (
                    x.type == 'datetime' ||
                    x.type === 'varchar' ||
                    x.type === 'nvarchar' || x.type === 'Input'
                ) {
                    // const cell = sheet.getCell(-1, y);
                    // cell.locked(false).foreColor('#2a06ecd9');
                    // sheet.getRange(-1, y, 1, 1).locked(false);
                    x.formatter = '@';
                }

                const cell = sheet.getCell(-1, y);
                cell.foreColor('black');
                //cell.backColor('white');
                if ((x.IsWrite == '1' && x.WFStepSN.indexOf(this.StepSN) > -1) || x.prop == 'isChecked') {
                    cell.locked(false).foreColor('#2a06ecd9');
                    //cell.backColor('#45b97c');

                } else if (x.prop != 'isChecked') {

                }

                sheet.options.protectionOptions.allowResizeColumns = true;
                sheet.options.isProtected = true;
                sheet.options.protectionOptions.allowResizeColumns = true;
                sheet.options.protectionOptions.allowInsertRows = true;
                sheet.options.protectionOptions.allowDeleteRows = true;
                sheet.options.protectionOptions.allowSelectLockedCells = true;
                sheet.options.protectionOptions.allowSelectUnlockedCells = true;
                sheet.options.protectionOptions.allowDeleteColumns = true;
                sheet.options.protectionOptions.allowInsertColumns = true;
                sheet.options.protectionOptions.allowDargInsertRows = true;
                sheet.options.protectionOptions.allowDragInsertColumns = true;
                sheet.options.protectionOptions.allowSort = true;
                sheet.options.protectionOptions.allowFilter = true;
                sheet.options.allowUserDragDrop = true;
                //行，start,end
                // if (x.isEdit) {
                //   sheet.getCell(-1, y).locked(false).foreColor("#2a06ecd9");
                // }

                // for (var i = 0; i < sheet.getRowCount(); i++) {

                //   const cell = sheet.getCell(i, y);
                //   cell.foreColor('black');
                // //cell.backColor('white');
                //   if(x.IsWrite == '1'&&x.WFStepSN.indexOf(this.StepSN)>-1)
                //   {
                //     cell.locked(false).foreColor('#2a06ecd9');

                //   }else if(x.prop!='isChecked')
                //   {

                //   }


                // }


            }

            );

            sheet.bindColumns(tableCols); //此方法一定要放在setDataSource后面才能正确渲染列名
            sheet.setRowCount(1, GC.Spread.Sheets.SheetArea.colHeader);
            colHeader1.forEach(function (value, index) {
                sheet.setValue(0, index, value, GC.Spread.Sheets.SheetArea.colHeader);


            });


            /////////////////表格事件/////////////
            //绑定表格事件前，需清除之前的绑定事件
            this.spread[remarkTb].unbindAll();
            this.spread[remarkTb].bind(GCsheets.Events.ButtonClicked, (e, args) => {
                const { sheet, row, col } = args;
                const cellType = sheet.getCellType(row, col);
                if (cellType instanceof GCsheets.CellTypes.Button) {
                }
                if (cellType instanceof GCsheets.CellTypes.CheckBox) {

                    this.Indexs = row;


                }

                if (cellType instanceof GCsheets.CellTypes.HyperLink) {
                }
            });

            this.spread[remarkTb].options.allowContextMenu = true;
            var insertRowsCopyStyle = {
                canUndo: true,
                name: 'insertRowsCopyStyle',
                execute: function (context, options, isUndo) {
                    var Commands = GC.Spread.Sheets.Commands;
                    if (isUndo) {
                        Commands.undoTransaction(context, options);
                        return true;
                    } else {
                        sheet.suspendPaint();
                        sheet.addRows(options.activeRow, _this.sheetSelectRows.length);
                        //  sheet.setArray(options.activeRow, 0,_this.sheetSelectRows);
                        // console.log(_this.sheetSelectRows);

                        // console.log(_this.sheetSelectObj.start+_this.sheetSelectRows.length)
                        //删除旧行
                        if (_this.sheetSelectObj.start > options.activeRow) {
                            //说明从下面插入上面
                            sheet.copyTo(
                                _this.sheetSelectObj.start + _this.sheetSelectRows.length,
                                0,
                                options.activeRow,
                                0,
                                _this.sheetSelectRows.length,
                                sheet.getColumnCount(),
                                GC.Spread.Sheets.CopyToOptions.all,
                            );

                            //   sheet.setArray(options.activeRow, 0, _this.sheetSelectRows);
                            sheet.deleteRows(
                                _this.sheetSelectObj.start + _this.sheetSelectRows.length,
                                _this.sheetSelectObj.count,
                            );
                            // sheet.removeRow(_this.sheetSelectObj.start+ _this.sheetSelectRows.length)
                        } else {
                            //从上面往下面插入
                            sheet.copyTo(
                                _this.sheetSelectObj.start,
                                0,
                                options.activeRow,
                                0,
                                _this.sheetSelectRows.length,
                                sheet.getColumnCount(),
                                GC.Spread.Sheets.CopyToOptions.all,
                            );
                            //  sheet.setArray(options.activeRow, 0, _this.sheetSelectRows);
                            sheet.deleteRows(
                                _this.sheetSelectObj.start,
                                _this.sheetSelectObj.count,
                            );
                        }
                        let count = sheet.getRowCount(GC.Spread.Sheets.SheetArea.viewport);

                        let lineID = _this.sheetSelectRows[remarkTb][lineIDIndex];
                        let isFind = false;
                        let viewSort = 1;

                        for (var i = 0; i < count; i++) {
                            if (isFind == false && sheet.getValue(i, lineIDIndex) == lineID) {
                                isFind = true;
                            }
                            if (isFind && sheet.getValue(i, lineIDIndex) != lineID) {
                                break;
                            }
                            if (isFind) {
                                sheet.setValue(i, viewSortIndex, viewSort);
                                viewSort++;
                            }
                        }

                        // Commands.startTransaction(context, options);

                        // sheet.suspendPaint();

                        // var beforeRowCount = 0;

                        //  sheet.suspendPaint();

                        // Commands.endTransaction(context, options);
                        sheet.resumePaint();

                        return true;
                    }
                },
            };

            this.spread[remarkTb]
                .commandManager()
                .register('insertRowsCopyStyle', insertRowsCopyStyle);

            function MyContextMenu() { }
            MyContextMenu.prototype = new GC.Spread.Sheets.ContextMenu.ContextMenu(
                this.spread[remarkTb],
            );
            MyContextMenu.prototype.onOpenMenu = function (
                menuData,
                itemsDataForShown,
                hitInfo,
                spread,
            ) {
                itemsDataForShown.forEach(function (item, index) {
                    // console.log(item);
                    if (item && item.name === 'gc.spread.rowHeaderinsertCutCells') {
                        item.command = 'insertRowsCopyStyle';
                    }
                    //  else if (item && item.name === "gc.spread.cut") {

                    //     item.command = "insertRowsCut";
                    //   }
                });
            };
            var contextMenu = new MyContextMenu();
            this.spread[remarkTb].contextMenu = contextMenu;


            // 列筛选
            // 参数2 开始列
            // 参数3
            // 参数4 结束列
            let cellrange = new GC.Spread.Sheets.Range(
                -1,
                -1,
                -1,
                tableCols.length,
            );
            let hideRowFilter = new GC.Spread.Sheets.Filter.HideRowFilter(cellrange);
            sheet.rowFilter(hideRowFilter)

            //居中
            // let count = sheet.getRowCount(GC.Spread.Sheets.SheetArea.viewport);
            // let style = new GC.Spread.Sheets.Style();
            // style.hAlign = GC.Spread.Sheets.HorizontalAlign.center;
            // style.vAlign = GC.Spread.Sheets.VerticalAlign.bottom;

            // //下拉搜索
            // let rowFilter = sheet.rowFilter();
            // tableCols.forEach((v, i) => {
            //     // if (v.IsSearch != 1) rowFilter.filterButtonVisible(i, false);
            //     if (!v.ValueMember) {
            //         for (let j = 0; j < count; j++) {
            //             sheet.setStyle(j, i, style);
            //         }
            //     }
            // })
            //头宽
            sheet.setColumnWidth(0, 26.0, GC.Spread.Sheets.SheetArea.rowHeader);



            sheet.resumePaint();
            // 变更行头宽度
        },
        async searchData() {
            // if (!this.FCUSTID) {
            //     this.$message.warning('请先选择客户')
            //     return
            // }
            // this.SearchSSN.FCUSTID=this.FCUSTID;
            // this.SearchSSN.jsWhere = `and FCUSTID = '${this.FCUSTID}'`
            // if (this.SearchData.Name) this.SearchSSN.jsWhere = `${this.SearchSSN.jsWhere} and Name = '${this.SearchData.Name}' `
            // if (this.SearchData.Customer) this.SearchSSN.jsWhere = `${this.SearchSSN.jsWhere} and Customer = '${this.SearchData.Customer}' `
            // if (this.SearchData.ProductNo) this.SearchSSN.jsWhere = `${this.SearchSSN.jsWhere} and ProductNo = '${this.SearchData.ProductNo}' `
            // if (this.SearchData.ModifyedOn) this.SearchSSN.jsWhere = `${this.SearchSSN.jsWhere} and ModifyedOn = '${this.SearchData.ModifyedOn[0]}' `
            // debugger
            // this.SearchSSN
            // debugger
            const res = await getDataList({ data: JSON.stringify(this.SearchSSN) });
            this.tableDataCode = res.data.Table
            this.setData(1, this.tableColsCode, [])
            this.setData(1, this.tableColsCode, this.tableDataCode)
            // debugger
            this.SearchSSN.total = res.data.Table1[0].RecordCount
        },
        async addSerial() {
            let sheet = this.spread[1].getActiveSheet();
            let count = sheet.getRowCount(GC.Spread.Sheets.SheetArea.viewport);
            let checkedRows = [];
            for (let row = 0; row < count; row++) {
                let cell = sheet.getCell(row, 0);
                if (cell.value() === true) {
                    checkedRows.push(row);
                }
            }
            if (checkedRows.length != 1) {
                this.$message.warning('请选一条数据')
                return
            }
            this.SearchSSN.jsWhere = `and  ProductNo = '${this.tableDataCode[0].ProductNo}' and FCUSTID = '${this.FCUSTID}' `
            const resCols = await getDataList({ data: JSON.stringify(this.SearchSSN) });
            let data = resCols.data.Table
            //添加不重复的
            data.forEach(obj => {
                if (this.tableDataThree.length != 0) {
                    if (this.tableDataThree.some(v => v.ID == obj.ID)) { }
                    else {
                        this.tableDataThree.push(JSON.parse(JSON.stringify(obj)))
                    }
                } else {
                    this.tableDataThree.push(JSON.parse(JSON.stringify(obj)))
                }

            })
            this.SearchBody.total = this.tableDataThree.length
            this.setData(2, this.tableColsThree, [])
            this.setData(2, this.tableColsThree, this.tableDataThree)
        },
        autoOrder() {
            this.tableDataCode.forEach(obj => {
                if (this.tableDataThree.length != 0) {
                    if (this.tableDataThree.some(v => v.ID == obj.ID)) { }
                    else {
                        this.tableDataThree.push(JSON.parse(JSON.stringify(obj)))
                    }
                } else {
                    this.tableDataThree.push(JSON.parse(JSON.stringify(obj)))
                }

            })
            this.SearchBody.total = this.tableDataThree.length
            this.setData(2, this.tableColsThree, [])
            this.setData(2, this.tableColsThree, this.tableDataThree)
        },
        pushOrder() {
            if (this.tableDataThree.length == 0) {
                this.$message.warning('请先添加数据')
                return
            }
            this.$emit('FunrRowsAdd', this.tableDataThree, this.ParmType);
        },
        addOrder() {
            let sheet = this.spread[1].getActiveSheet();
            let count = sheet.getRowCount(GC.Spread.Sheets.SheetArea.viewport);
            let checkedRows = [];
            for (let row = 0; row < count; row++) {
                let cell = sheet.getCell(row, 0);
                if (cell.value() === true) {
                    checkedRows.push(row);
                }
            }
            if (checkedRows.length == 0) {
                this.$message.warning('请选择数据')
                return
            }
            checkedRows.forEach(i => {
                if (this.tableDataThree.length != 0) {
                    if (this.tableDataThree.some(v => v.ID == this.tableDataCode[i].ID)) { }
                    else {
                        this.tableDataThree.push(JSON.parse(JSON.stringify(this.tableDataCode[i])))
                    }
                } else {
                    this.tableDataThree.push(JSON.parse(JSON.stringify(this.tableDataCode[i])))
                }

            })
            this.SearchBody.total = this.tableDataThree.length
            this.setData(2, this.tableColsThree, [])
            this.setData(2, this.tableColsThree, this.tableDataThree)
        },
        async addHead() {
            const result = await UpdateForm({
                IsPostBack: false,
                InterID: this.SearchSSN.InterID,
            });
            this.tableDataCode.push(result.data1.Table[0])
        },
        handleInput(value) {
            if (value == 1) {
                this.tableDataCode = this.tableDataCodeSave.filter(v => v.PRINTEDTIMES == 1)
            } else {
                this.tableDataCode = this.tableDataCodeSave.filter(v => v.PRINTEDTIMES != 1)
            }
        },
        handselectCode(row) {
            this.selectCode = row
            // debugger
        },
        onSubmit() {
        },
        //搜索重置
        refresh() {
            // alert(this.SearchSSN.page)
            this.handrowclick();
        },
        reform() {
            this.Search = {
                // 查询条件
                // total: 0, // 总记录数
                pageSize: 14, // 一页显示的记录数
                page: 1, // /当前页码
                RNO: "4", // 表编号  根据Controller中对应的表编号
                jsWhere: "", // 自定义条件

            };
            this.getDataListCe();
        },
        async getDataList() {
            const res = await getDataList({ data: JSON.stringify(this.SearchWO) });
            this.tableData = res.data.Table;
            this.tableCols = res.data1;


            this.setData(0, this.tableCols, this.tableData);
            let sheet = this.spread[0].getActiveSheet();
            //绑定点击事件
            sheet.bind(GC.Spread.Sheets.Events.CellClick, (sender, args) => this.handrowclick(args));
            // debugger

            this.SearchSSN.jsWhere = `and  1 = 2`
            const resCols = await getDataList({ data: JSON.stringify(this.SearchSSN) });
            this.tableColsCode = resCols.data1;
            let row = {
                prop: 'isChecked',
                label: '选择',
                width: 80,
                IsWrite: 1,
                WFStepSN: '-1',
                type: '',
                IsSearch: '0'
                // RowFilterBase. filterButtonVisible
            };
            this.tableColsCode.unshift(row);
            // debugger

            this.SearchBody.jsWhere = `and  1 = 2`
            const resThree = await getDataList({ data: JSON.stringify(this.SearchBody) });
            this.tableColsThree = resThree.data1;
            // debugger
        },
        OpenFindForm() {
            //打开搜索框
            this.SearchDialog = true;
            //计算外边距
            console.log(this.$refs.searchDialog.offsetHeight);
            this.DialogBtnMargin = this.$refs.searchDialog.offsetHeight - 40;
        }, handlexportData() {
            funDownload("334", JSON.stringify(this.Search));
        }, handleIsfunEdit() {
            this.IsfunEdit = true;
        }, handleIsfunfail() {
            this.Isfunfail = true;
        }, async handeAdd() {
            // 新建

            let routeUrl = this.$router.push({
                path: "/System/PageAutoForm",
                query: { billID: "", IsPostBack: false },
            });
            window.open(routeUrl.path, "_top");

        },
        async handleEdit(scope) {
            // 修改

            let routeUrl = this.$router.push({
                path: "/System/PageAutoForm",
                query: { billID: scope.row.InterID, IsPostBack: false },
            });
            window.open(routeUrl.href, "_top");

            this.inputName = row.InterID;


        },
        delData() {
            this.$confirm('删除操作, 是否继续?', '提示', {
                confirmButtonText: "确认",
                cancelButtonText: "取消",
            })
                .then(async () => {

                    this.spread[0].suspendPaint();
                    let sheet = this.spread[0].getActiveSheet();
                    sheet.deleteRows(this.Indexs, 1);
                    sheet.resumePaint()
                    // debugger
                    for (var row of this.selectionData) {



                        //

                        const result = await DeletForm({
                            billID: row.IDXNO,
                            IsPostBack: false,
                        });

                        this.$message({
                            type: "success",
                            message: result.msg,
                        });

                    }

                    this.getDataList();

                })
                .catch((err) => {
                    console.error(err);
                });

        },
        async handrowclick(args) {
            // debugger
            if (args) {
                this.FCUSTID = this.tableData[args.row].FCUSTID
                this.SearchSSN.Customer = this.tableData[args.row].Customer
                this.SearchSSN.FCUSTID = this.tableData[args.row].FCUSTID
                this.SearchSSN.jsWhere = `and FCUSTID = '${this.tableData[args.row].FCUSTID}'`
            }
            const resCols = await getDataList({ data: JSON.stringify(this.SearchSSN) });
            this.tableDataCode = resCols.data.Table
            this.SearchSSN.total = resCols.data.Table1[0].RecordCount;
            // this.SearchSSN
            // debugger

            this.setData(1, this.tableColsCode, this.tableDataCode);
            // let sheet = this.spread[1].getActiveSheet();
            // sheet.bind(GC.Spread.Sheets.Events.CellClick,(sender, args)=> this.handrowclick(args));
            // debugger
            this.key = this.key + 1

        },
        handleclose() {


            if (this.billID != "") {

                this.$confirm('关单操作, 是否继续? 订单号：' + this.billID, '提示', {
                    confirmButtonText: "确认",
                    cancelButtonText: "取消",
                })
                    .then(async () => {



                        const result = await CloseForm({

                            billID: this.billID,
                            types: 1,
                            IsPostBack: false,
                        });
                        this.getDataListCe();
                        this.$message({
                            type: "success",
                            message: result.msg,
                        });

                    })
                    .catch((err) => {
                        console.error(err);
                    });
            } else {
                this.$notify({
                    title: "关单操作，请选择数据" + this.billID,
                    dangerouslyUseHTMLString: true,
                    message: "",
                    type: "error",
                });
            }



        },


    }
}
</script>

<style lang="scss" scoped>
.ces-mainopen {
    display: flex;
    flex-wrap: wrap;
    height: 100%;

    // width: 98vw;
    .botn {
        margin: 2px 0 2px 2px;
    }

    .main {
        // flex: 1;
        background-color: #fff;
        border-radius: 4px;
        padding: 4px;
        margin-bottom: 4px;
        height: 40vh;

        .inp {
            float: right;
            // display: inline-block;
            width: 100px;
            margin-left: 2px;
            transform: translateY(2px);
        }

        /deep/ .el-radio__label {
            font-size: 12px
        }

        .check {
            margin-left: 12px;
            transform: translateY(2px);
            margin-right: 0;
            padding-top: 8px;
            width: 66px;

        }

        /deep/ .vxe .el-input__inner {
            height: 22px;
        }



        .float {
            float: right;
        }
    }
}

.dialog {

    /deep/ .el-dialog {
        margin-top: 50vh !important;
        transform: translateY(-50%);
    }

    table {
        width: 100%;
        border-collapse: collapse;

        /* 合并相邻的边框 */
        td {
            border: 1px solid #000;
            padding: 15px;
            /* 添加内边距 */
            text-align: left;
            /* 文字左对齐 */
        }

        tr td:first-child {
            width: 30%;
        }

    }
}



.app-container {
    position: relative;
    background-color: rgb(255, 255, 255);

    // padding-bottom: 100px;
    .botton {
        float: right;
        padding-top: 8px;
        padding-right: 6px;
    }

    .EditObjs-table {
        margin-top: 30px;
    }

    .permission-tree {
        margin-bottom: 5px;
    }
}

.searchDialog ::v-deep .el-dialog__header {
    background: #409eff;
}

.searchDialog ::v-deep .el-dialog__title {
    color: #fff;
}

.searchDialog ::v-deep .el-dialog__headerbtn .el-dialog__close {
    color: #fff;
}
</style>